package Ar;

import java.util.Arrays;

/**
 * @Author MDD
 * @Description
 * @Version
 * @Date
 **/

// N个数字来排队，两两相比小靠前
// 外层循环N-1 ，内层循环N-i-1
// 升序降序加if > 升序  < 降序

public class bubbleSort {
    public static void main(String[] args) {
        int [] ar = {16,90,25,23,9};
        System.out.println("排序前的数组:"+ Arrays.toString(ar));
        int temp = 0;

        for (int i = 0; i < ar.length-1; i++) {
            for (int j = 0; j < ar.length-i-1; j++) {
                if (ar[j]>ar[j+1]){//升序排列  如果想降序就改为ar[j]<ar[j+1]
                    temp = ar[j];
                    ar[j] = ar[j+1];
                    ar[j+1] = temp;
                }
            }
        }
        System.out.println("排序后的数组:"+ Arrays.toString(ar));
    }
}
